﻿using Mapster;

namespace Agile.Infra.Core.Agile.Extensions;

public static class MapsterExtension
{
    /// <summary>类型映射</summary>
    public static TDestination MapTo<TDestination>(this object source)
    => MapTo<TDestination>(source, TypeAdapterConfig.GlobalSettings);

    /// <summary>类型映射</summary>
    public static TDestination MapTo<TDestination>(this object source, TypeAdapterConfig adapterConfig)
    => source.Adapt<TDestination>(adapterConfig);

    /// <summary> 类型映射 (映射到现有对象) </summary>
    public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination tDestination)
    => source.Adapt(tDestination);

    /// <summary>集合列表类型映射</summary>
    public static List<TDestination> MapToList<TDestination>(this IEnumerable source)
    => MapToList<TDestination>(source, TypeAdapterConfig.GlobalSettings);

    /// <summary>集合列表类型映射</summary>
    public static List<TDestination> MapToList<TDestination>(this IEnumerable source, TypeAdapterConfig adapterConfig)
    => source.Adapt<List<TDestination>>(adapterConfig);

    /// <summary>对象属性映射</summary>
    public static void MapTo(this object @this, object destObject)
    => @this.Adapt(destObject);
}
